<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class StoreCouponProduct extends Model

{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     *可批量赋值的字段
     */
    public $fillable = [
        'coupon_id',
        'product_id',
    ];

    /**
     * 默认倒序排序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 可搜索的字段
     */
    public $searchable = [
        'coupon_id',
        'product_id',
    ];

    /**
     * 优惠卷模板关联所属的id
     */
    public function coupon(){
        return $this->hasMany(StoreCouponIssue::class,'coupon_id','id');
    }

    /**
     * 优惠卷模板关联所属的商品
     */
    public function product(){
        return $this->hasMany(Product::class,'product_id','id');
    }
}
